package com.example.demo_text;

import java.io.*;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

@WebServlet("/login")
public class GuestLoginServlet extends HttpServlet {
    private static final String GUEST_USERNAME = "Guest";
    private static final String GUEST_PASSWORD = "guestpassword";

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        if (GUEST_USERNAME.equals(username) && GUEST_PASSWORD.equals(password)) {
            // 登录成功，重定向到欢迎页面
            response.sendRedirect("home.jsp");
        } else {
            // 登录失败，返回错误信息
            request.setAttribute("errorMessage", "Invalid username or password");
            request.getRequestDispatcher("login.jsp").forward(request, response);
        }
    }
}
